/**
 * Validate.js
 *
 *
 */

var cs441GoogleMapsViz = cs441GoogleMapsViz || {};

cs441GoogleMapsViz.Validator = function () {
    this.validateFields = function() {
	return cs441GoogleMapsViz.validateFields();
    }
}



cs441GoogleMapsViz.validateFields = function() {
    cs441GoogleMapsViz.validateGPA();
    cs441GoogleMapsViz.validateSATMath();
    cs441GoogleMapsViz.validateSATVerbal();
    cs441GoogleMapsViz.validateZip();
 }

cs441GoogleMapsViz.validateGPA = function() {
 //Check GPA
    var gpa_low = $("#gpa-low").val();
    var gpa_high = $("#gpa-high").val();
    
    if(!(/^(([0-3](\.\d\d?)?)|4(\.00?)?)$/.test(gpa_low)))
    {
	//alert("!");
	$("#gpa-low").val("0.00");
    }
    if(!(/^(([0-3](\.\d\d?)?)|4(\.00?)?)$/.test(gpa_high)))
    {
	$("#gpa-high").val("4.00");
    }
    gpa_low = parseFloat($("#gpa-low").val());
    gpa_high = parseFloat($("#gpa-high").val());
    if (gpa_low > gpa_high) {	
	$("#gpa-low").val("0.00");
    }
}

cs441GoogleMapsViz.validateSATMath = function () {
   //Check SAT Math
    var sat_math_low = $("#sat-math-low").val();
    var sat_math_high = $("#sat-math-high").val();

    if(!(/^[0-8]?[0-9]?[0-9]$/.test(sat_math_low)))
    {
	$("#sat-math-low").val("200");
    }
    if(!(/^[0-8]?[0-9]?[0-9]$/.test(sat_math_high)))
    {
	$("#sat-math-high").val("800");
    }
    sat_math_low = parseInt($("#sat-math-low").val());
    sat_math_high = parseInt($("#sat-math-high").val());
    if (sat_math_low > sat_math_high) {	
	$("#sat-math-low").val("200");
    }
 
}

cs441GoogleMapsViz.validateSATVerbal = function() {
   //Check SAT Reading
    var sat_reading_low = $("#sat-reading-low").val();
    var sat_reading_high = $("#sat-reading-high").val();
    
    if(!(/^[0-8]?[0-9]?[0-9]$/.test(sat_reading_low)))
    {
	$("#sat-reading-low").val("200");
    }
    if(!(/^[0-8]?[0-9]?[0-9]$/.test(sat_reading_high)))
    {
	$("#sat-reading-high").val("800");
    }
    sat_math_low = parseInt($("#sat-reading-low").val());
    sat_math_high = parseInt($("#sat-reading-high").val());
    if (sat_reading_low > sat_reading_high) {	
	$("#sat-reading-low").val("200");
    }
}

cs441GoogleMapsViz.validateZip = function() {
    
}